package monitor

import (
	"fmt"
	"github.com/shirou/gopsutil/cpu"
	"github.com/shirou/gopsutil/load"
	"time"
)

type CPU struct {
}

func (c *CPU) Info() {
	//打印cpu相关信息
	info, _ := cpu.Info()
	for _, ci := range info {
		fmt.Println(ci)
	}

	//打印cpu使用率,每5秒一次，总共9次
	for i := 1; i < 10; i++ {
		time.Sleep(time.Millisecond * 5000)
		percent, _ := cpu.Percent(time.Second, false)
		fmt.Printf("%v, cpu percent: %v", i, percent)
	}

	//显示cpu load值
	avg, _ := load.Avg()
	fmt.Println(avg)
}
